package com.numberone.system.service.impl;

import com.numberone.system.domain.TypeFirst;
import com.numberone.system.domain.TypeFirstInfo;
import com.numberone.system.domain.TypeSecond;
import com.numberone.system.domain.TypeThird;
import com.numberone.system.mapper.TypeFirstInfoMapper;
import com.numberone.system.mapper.TypeFirstMapper;
import com.numberone.system.mapper.TypeSecondMapper;
import com.numberone.system.mapper.TypeThirdMapper;
import com.numberone.system.service.ITypeListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

@Service
public class TypeListServiceImpl implements ITypeListService {

    @Autowired
    private TypeFirstMapper typeFirstMapper;
    @Autowired
    private TypeSecondMapper typeSecondMapper;
    @Autowired
    private TypeThirdMapper typeThirdMapper;
    @Autowired
    private TypeFirstInfoMapper typeFirstInfoMapper;

    @Override
    public List<TypeFirst> selectTypeList() {

        //3级
        List<TypeThird> TypeThirdList = typeThirdMapper.selectTypeThirdList(null);
        //2级
        List<TypeSecond> typeSecondList = typeSecondMapper.selectTypeSecondList(null);
        for (TypeSecond i :typeSecondList)
        {
            List<TypeThird> list = new LinkedList<>();
            for (TypeThird j : TypeThirdList)
            {
                if (j.getPId() == i.getId())
                {
                    list.add(j);
                }
            }
            i.setTypeThirdList(list);
        }
        List<TypeFirst> typeFirstList = typeFirstMapper.selectTypeFirstList(null);
        List<TypeFirstInfo> typeFirstInfos = typeFirstInfoMapper.selectTypeFirstInfoList(null);
        for (TypeFirst i :typeFirstList)
        {
            List<TypeSecond> list = new LinkedList<>();
            List<TypeFirstInfo> infoList = new LinkedList<>();
            for (TypeSecond j : typeSecondList)
            {
                if (j.getPId() == i.getId())
                {
                    list.add(j);
                }
            }
            i.setTypeSecondList(list);
            for (TypeFirstInfo q : typeFirstInfos)
            {
                if (q.getTypeFirstId() == i.getId() )
                {
                    infoList.add(q);
                }
            }
            i.setTypeFirstInfoList(infoList);
        }

        return typeFirstList;
    }
}
